package com.telit.firecommand.controller;

import com.telit.common.entity.DataReturn;
import com.telit.common.enums.ResultCode;
import com.telit.firecommand.dto.FireSituationListDTO;
import com.telit.firecommand.service.FireSituationService;
import com.telit.firecommand.vo.FireSituationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Create by Chencf 2022/9/22
 */
@RestController
@Api(tags = "抢险救援火场态势相关接口",description = "/fire-situation")
@RequestMapping("/fire-situation")
public class FireSituationController {
    private static Logger logger = LoggerFactory.getLogger(FireSituationController.class);

    @Autowired
    private FireSituationService fireResourceService;

    //查询火情列表
    @GetMapping("/queryFireSituationByCondition")
    @ApiOperation("/指挥调度查询火情列表")
    public DataReturn queryFireSituationByCondition(FireSituationListDTO fireSituationListDTO){
        Object object=fireResourceService.queryFireSituationByCondition(fireSituationListDTO);
        return DataReturn.ok(object);
    }


//    //判断是否可以调用开始扑救接口
//    @GetMapping(value = "/isOkRescue")
//    @ApiOperation("判断是否可以调用启动响应接口   true可以 false不行")
//    public DataReturn<Boolean> isOkRescue(@RequestParam(value = "districtCode",required = false) String districtCode,
//                                           @RequestParam(value = "fireId",required = false) String fireId) {
//        Boolean isRescue = fireResourceService.isOkRescue(districtCode,fireId);
//        return DataReturn.ok(isRescue);
//    }
//
//    //
//
//    @GetMapping(value = "/releaseRescue")
//    @ApiOperation("点击完成扑救的时候判断是否能点击   true可以 false不行")
//    public DataReturn<CommAlarmRescueVO> releaseRescue(@RequestParam(value = "districtCode",required = false) String districtCode,
//                                                       @RequestParam(value = "fireId",required = false) String fireId) {
//        CommAlarmRescueVO commAlarmRescueVO = fireResourceService.releaseRescue(districtCode,fireId);
//        return DataReturn.ok(commAlarmRescueVO);
//    }


    @ApiOperation(value = "01-----火场态势周围资源查询-需要字段返回 flag表示资源所属的分类 1机构人员  2 基础设施  3 阻隔系统  4 其他设施 ")
    @GetMapping(value = "/getSimpleGeoSourceNearbyRadius",produces = "application/json;charset=UTF-8")
    public DataReturn getSimpleGeoSourceNearbyRadius(@RequestParam(value = "longitude", required = false) String longitude,
                                               @RequestParam(value = "latitude", required = false) String latitude,
                                               @RequestParam(value = "radius", required = false) String radius,
                                               @RequestParam(value = "flag", required = false) String flag,
                                               @RequestParam(value = "districtCode", required = false) String districtCode
    ){
        try {
            Map<String, List<FireSituationVO>> geoSourceNearbyRadiusMap = fireResourceService.getSimpleGeoSourceNearbyRadius(longitude, latitude, radius, flag, districtCode);
            return DataReturn.ok(geoSourceNearbyRadiusMap);
        }catch (Exception e){
            logger.error("获取火场态势周围资源个别字段失败,e:{}",e.getMessage());
            return DataReturn.failure(ResultCode.SERVER_ERROR,"查询火场态势周围资源个别失败");
        }
    }


    /**
     * 火场态势周围人员设备查询（无人机、飞手、视频监控、护林员）,加数据权限
     * @param longitude
     * @param latitude
     * @param radius
     * @param flag
     * @return
     */
    @ApiOperation(value = "02---火场态势周围人员设备查询（无人机、飞手、视频监控、护林员）")
    @GetMapping(value = "/getPeopleEquNearbyRadius",produces = "application/json;charset=UTF-8")
    public DataReturn getPeopleEquNearbyRadius(@RequestParam(value = "longitude", required = false) String longitude,
                                               @RequestParam(value = "latitude", required = false) String latitude,
                                               @RequestParam(value = "radius", required = false) String radius,
                                               @RequestParam(value = "flag", required = false) String flag){
        try {
            Map<String, List> peopleEquNearbyRadiusMap = fireResourceService.getPeopleEquNearbyRadius(longitude, latitude, radius,flag);
            return DataReturn.ok(peopleEquNearbyRadiusMap);
        }catch (Exception e){
            logger.error("获取火场态势周围资源失败,e:{}",e.getMessage());
            return DataReturn.failure(ResultCode.SERVER_ERROR,"查询火场态势周围资源失败");
        }
    }

}
